package com.ruoyi.web.controller.website;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.module.domain.MaterialRecord;
import com.ruoyi.module.service.IMaterialRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程学习记录Controller
 *
 * @author fubojin
 * @date 2025-03-05
 */
@RestController
@RequestMapping("/module/materialRecord")
public class WebMaterialRecordController extends BaseController
{
    @Autowired
    private IMaterialRecordService materialRecordService;

    /**
     * 查询课程学习记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MaterialRecord materialRecord)
    {
        startPage();
        List<MaterialRecord> list = materialRecordService.selectMaterialRecordList(materialRecord);
        return getDataTable(list);
    }

    /**
     * 根据用户ID查询课程学习记录
     */
    @GetMapping("/userId")
    public AjaxResult getInFoByUserId(@RequestParam Long userId)
    {
        return success(materialRecordService.selectMaterialRecordByUserId(userId));
    }

    /**
     * 导出课程学习记录列表
     */
    @Log(title = "课程学习记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialRecord materialRecord)
    {
        List<MaterialRecord> list = materialRecordService.selectMaterialRecordList(materialRecord);
        ExcelUtil<MaterialRecord> util = new ExcelUtil<MaterialRecord>(MaterialRecord.class);
        util.exportExcel(response, list, "课程学习记录数据");
    }

    /**
     * 获取课程学习记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(materialRecordService.selectMaterialRecordById(id));
    }

    /**
     * 新增课程学习记录
     */
    @Log(title = "课程学习记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialRecord materialRecord)
    {
        return toAjax(materialRecordService.insertMaterialRecord(materialRecord));
    }

    /**
     * 修改课程学习记录
     */
    @Log(title = "课程学习记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialRecord materialRecord)
    {
        return toAjax(materialRecordService.updateMaterialRecord(materialRecord));
    }

    /**
     * 删除课程学习记录
     */
    @Log(title = "课程学习记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(materialRecordService.deleteMaterialRecordByIds(ids));
    }
}
